<!DOCTYPE html><html lang="[&quot;zh-Hans&quot;,&quot;zh-CN&quot;,&quot;default&quot;]"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="git常用命令记录"><meta name="keywords" content="git"><meta name="author" content="wenmu"><meta name="copyright" content="wenmu"><title>git常用命令记录 | 温木的博客</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.6.1"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.6.1"><link rel="dns-prefetch" href="https://cdn.staticfile.org"><link rel="dns-prefetch" href="https://cdn.bootcss.com"><link rel="dns-prefetch" href="https://creativecommons.org"><link rel="dns-prefetch" href="http://ta.qq.com"><script>(function() {
   var hm = document.createElement("script");
   hm.src = "https://tajs.qq.com/stats?sId=&lt;script type=&quot;text/javascript&quot; src=&quot;http://tajs.qq.com/stats?sId=66523541&quot; charset=&quot;UTF-8&quot;&gt;&lt;/script&gt;";
   var s = document.getElementsByTagName("script")[0];
   s.parentNode.insertBefore(hm, s);
 })();</script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  }
} </script><meta name="generator" content="Hexo 4.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-全局设置"><span class="toc-number">1.</span> <span class="toc-text">Git 全局设置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#创建新版本库"><span class="toc-number">2.</span> <span class="toc-text">创建新版本库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#本地已存在的项目"><span class="toc-number">3.</span> <span class="toc-text">本地已存在的项目</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#已存在的-Git-版本库"><span class="toc-number">4.</span> <span class="toc-text">已存在的 Git 版本库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#另一种关联方式"><span class="toc-number">5.</span> <span class="toc-text">另一种关联方式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#查看分支是根据哪个分支创建的"><span class="toc-number">6.</span> <span class="toc-text">查看分支是根据哪个分支创建的</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#更新代码"><span class="toc-number">7.</span> <span class="toc-text">更新代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#提交代码"><span class="toc-number">8.</span> <span class="toc-text">提交代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#切换到远程其他分支"><span class="toc-number">9.</span> <span class="toc-text">切换到远程其他分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#以当前分支创建新的分支"><span class="toc-number">10.</span> <span class="toc-text">以当前分支创建新的分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#删除本地分支"><span class="toc-number">11.</span> <span class="toc-text">删除本地分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#查看本地配置信息"><span class="toc-number">12.</span> <span class="toc-text">查看本地配置信息</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#查看当前用户名和-email"><span class="toc-number">13.</span> <span class="toc-text">查看当前用户名和 email</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#更改-git-本地配置用户名"><span class="toc-number">14.</span> <span class="toc-text">更改 git 本地配置用户名</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#更改远程仓库地址"><span class="toc-number">15.</span> <span class="toc-text">更改远程仓库地址</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#查看合并到-master-上的分支"><span class="toc-number">16.</span> <span class="toc-text">查看合并到 master 上的分支</span></a></li></ol></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://i.loli.net/2020/02/27/xwaBoOj158MfNyq.jpg"></div><div class="author-info__name text-center">wenmu</div><div class="author-info__description text-center">记录一些在工作中或学习新知识时学到的一些知识点；正所谓好记性不如一个烂笔头，温故而知新！</div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">115</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">52</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">30</span></a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">温木的博客</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus"><a class="site-page" href="/">首页</a><a class="site-page" href="/archives">文章</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a></span></div><div id="post-info"><div id="post-title">git常用命令记录</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2020-03-05</time><span class="post-meta__separator">|</span><i class="fa fa-inbox post-meta__icon" aria-hidden="true"></i><a class="post-meta__categories" href="/categories/git/">git</a></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><h3 id="Git-全局设置"><a href="#Git-全局设置" class="headerlink" title="Git 全局设置"></a>Git 全局设置</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name <span class="string">"username"</span></span><br><span class="line">git config --global user.email <span class="string">"username@mail.com"</span></span><br></pre></td></tr></table></figure>

<h3 id="创建新版本库"><a href="#创建新版本库" class="headerlink" title="创建新版本库"></a>创建新版本库</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> http://gitlab-in.bingex.com/store/ss-oco.git</span><br><span class="line"><span class="built_in">cd</span> ss-oco</span><br><span class="line">touch README.md</span><br><span class="line">git add README.md</span><br><span class="line">git commit -m <span class="string">"add README"</span></span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<h3 id="本地已存在的项目"><a href="#本地已存在的项目" class="headerlink" title="本地已存在的项目"></a>本地已存在的项目</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> existing_folder</span><br><span class="line">git init</span><br><span class="line">git remote add origin http://gitlab-in.bingex.com/store/ss-oco.git</span><br><span class="line">git add .</span><br><span class="line">git commit -m <span class="string">"Initial commit"</span></span><br><span class="line">git pull origin master --allow-unrelated-historie</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<h3 id="已存在的-Git-版本库"><a href="#已存在的-Git-版本库" class="headerlink" title="已存在的 Git 版本库"></a>已存在的 Git 版本库</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> existing_repo</span><br><span class="line">git remote add origin http://gitlab-in.bingex.com/store/ss-oco.git</span><br><span class="line">git push -u origin --all</span><br><span class="line">git push -u origin --tags</span><br></pre></td></tr></table></figure>

<h3 id="另一种关联方式"><a href="#另一种关联方式" class="headerlink" title="另一种关联方式"></a>另一种关联方式</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">…or create a new repository on the <span class="built_in">command</span> line</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"# CouponCard"</span> &gt;&gt; README.md</span><br><span class="line">git init</span><br><span class="line">git add README.md</span><br><span class="line">git commit -m <span class="string">"first commit"</span></span><br><span class="line">git remote add origin https://github.com/codepandy/CouponCard.git</span><br><span class="line">git push -u origin master</span><br><span class="line">…or push an existing repository from the <span class="built_in">command</span> line</span><br><span class="line"></span><br><span class="line">git remote add origin https://github.com/codepandy/CouponCard.git</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<h3 id="查看分支是根据哪个分支创建的"><a href="#查看分支是根据哪个分支创建的" class="headerlink" title="查看分支是根据哪个分支创建的"></a>查看分支是根据哪个分支创建的</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reflog --data=<span class="built_in">local</span> --all | grep 要查询的分支名称</span><br></pre></td></tr></table></figure>

<h3 id="更新代码"><a href="#更新代码" class="headerlink" title="更新代码"></a>更新代码</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git pull</span><br></pre></td></tr></table></figure>

<h3 id="提交代码"><a href="#提交代码" class="headerlink" title="提交代码"></a>提交代码</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git add .</span><br><span class="line">git commit -am <span class="string">"提交说明"</span></span><br><span class="line">git push</span><br></pre></td></tr></table></figure>

<h3 id="切换到远程其他分支"><a href="#切换到远程其他分支" class="headerlink" title="切换到远程其他分支"></a>切换到远程其他分支</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b 本地分支名 origin/远程分支名</span><br></pre></td></tr></table></figure>

<h3 id="以当前分支创建新的分支"><a href="#以当前分支创建新的分支" class="headerlink" title="以当前分支创建新的分支"></a>以当前分支创建新的分支</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b NewBranch <span class="comment"># NewBranch 是新的分支名</span></span><br><span class="line">git push --<span class="built_in">set</span>-upstream origin NewBranch <span class="comment"># 把本地分支同步到远程仓库，--set-upstream缩写是-u</span></span><br></pre></td></tr></table></figure>

<h3 id="删除本地分支"><a href="#删除本地分支" class="headerlink" title="删除本地分支"></a>删除本地分支</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -D BranchName</span><br></pre></td></tr></table></figure>

<h3 id="查看本地配置信息"><a href="#查看本地配置信息" class="headerlink" title="查看本地配置信息"></a>查看本地配置信息</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --<span class="built_in">local</span> --list</span><br></pre></td></tr></table></figure>

<h3 id="查看当前用户名和-email"><a href="#查看当前用户名和-email" class="headerlink" title="查看当前用户名和 email"></a>查看当前用户名和 email</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config user.name</span><br><span class="line">git config user.email</span><br></pre></td></tr></table></figure>

<h3 id="更改-git-本地配置用户名"><a href="#更改-git-本地配置用户名" class="headerlink" title="更改 git 本地配置用户名"></a>更改 git 本地配置用户名</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config user.name <span class="string">'new_name'</span></span><br><span class="line">git config user.email <span class="string">'new_email'</span></span><br></pre></td></tr></table></figure>

<h3 id="更改远程仓库地址"><a href="#更改远程仓库地址" class="headerlink" title="更改远程仓库地址"></a>更改远程仓库地址</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote <span class="built_in">set</span>-url origin URL // 更换远程仓库地址，URL为新地址。</span><br></pre></td></tr></table></figure>

<h3 id="查看合并到-master-上的分支"><a href="#查看合并到-master-上的分支" class="headerlink" title="查看合并到 master 上的分支"></a>查看合并到 master 上的分支</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">git branch --merged master <span class="comment">#列出合并到母版中的分支</span></span><br><span class="line"></span><br><span class="line">git branch --merged    <span class="comment">#列出合并到HEAD中的分支（即当前分支的尖端）</span></span><br><span class="line"></span><br><span class="line">git branch --no-merged   <span class="comment">#列出尚未合并的分支</span></span><br><span class="line"></span><br><span class="line">默认情况下，这仅适用于本地分支。该-a标志将显示本地和远程分支，并且-r标志仅显示远程分支。</span><br></pre></td></tr></table></figure>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">wenmu</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://blog.wangpengpeng.site/2020/03/05/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E8%AE%B0%E5%BD%95/">http://blog.wangpengpeng.site/2020/03/05/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E8%AE%B0%E5%BD%95/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://blog.wangpengpeng.site">温木的博客</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/git/">git</a></div><div class="post-qr-code"><div class="post-qr-code-item"><img class="post-qr-code__img" src="https://i.loli.net/2020/02/27/hOBzIxFDJMCrmtN.jpg"><div class="post-qr-code__desc">微信打赏</div></div></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2020/03/05/react%E5%9C%A8ie%E4%B8%AD%E7%A9%BA%E7%99%BD%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/"><i class="fa fa-chevron-left">  </i><span>react在ie中空白解决方案</span></a></div><div class="next-post pull-right"><a href="/2020/03/04/package-json%E7%9A%84browserlist%E9%85%8D%E7%BD%AE/"><span>package.json的browserlist配置</span><i class="fa fa-chevron-right"></i></a></div></nav><div id="vcomment"></div><script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script><script src="https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js"></script><script>var notify = 'false' == true ? true : false;
var verify = 'false' == true ? true : false;
var GUEST_INFO = ['nick','mail','link'];
var guest_info = 'nick,mail,link'.split(',').filter(function(item){
  return GUEST_INFO.indexOf(item) > -1
});
guest_info = guest_info.length == 0 ? GUEST_INFO :guest_info;
window.valine = new Valine({
  el:'#vcomment',
  notify:notify,
  verify:verify,
  appId:'U1QqpeQNuBnRsfygHk1GQ30q-gzGzoHsz',
  appKey:'dunDQzEseDzgsKgw4qLQcog1',
  placeholder:'支持markdown！',
  avatar:'wavatar',
  guest_info:guest_info,
  pageSize:'20',
  lang: 'zh-cn'
})</script></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2019 - 2020 By wenmu</div><div class="framework-info"><span>驱动 - </span><a href="http://hexo.io" target="_blank" rel="noopener"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a href="https://github.com/Molunerfinn/hexo-theme-melody" target="_blank" rel="noopener"><span>Melody</span></a></div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv">该文访问量<span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.6.1"></script><script src="/js/fancybox.js?version=1.6.1"></script><script src="/js/sidebar.js?version=1.6.1"></script><script src="/js/copy.js?version=1.6.1"></script><script src="/js/fireworks.js?version=1.6.1"></script><script src="/js/transition.js?version=1.6.1"></script><script src="/js/scroll.js?version=1.6.1"></script><script src="/js/head.js?version=1.6.1"></script><script>if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
}</script></body></html>